home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 050a / tse_mac1.zip / SAVER1.ZIP / SAVER.S
Text File  |  1993-03-01  |  5KB  |  168 lines

  1. /**********************************************************************
  2.            ┌───────────────────────────────────────────────┐
  3.            │        Released into the public domain        │
  4.            │  20 April 1993 by the author, Rick VanNorman  │
  5.            └───────────────────────────────────────────────┘
  6.  
  7. This set of macros will save and restore editor status, including all
  8. bookmarks set and files in the edit ring.
  9.  
  10. Editor status, including video mode, bookmarks, and all files currently
  11. being edited, is saved on exit via mSaveStatAndExit().
  12.  
  13. On startup, if there are no parameters on the command tail and the file
  14. STATUS.TSE is available, the full editor status described by STATUS.TSE
  15. will be restored.  If no command tail and no STATUS.TSE the user will be
  16. prompted for a file to edit (as normal TSE).  If a command tail is
  17. present, STATUS.TSE is ignored and the editor is started fresh with the
  18. files specified by the user.
  19.  
  20. The startup sequence requires access to the dos command tail, gained via
  21. the DosCmdLine editor variable.
  22.  
  23. These routines could be extended to rebuild a multi-window display,
  24. restore command histories, or almost everything else; I don't need that
  25. level of functionality so I won't do it.
  26.  
  27. 20 April 1993
  28. Rick VanNorman
  29. Route 1 Box 294
  30. Glenwood, WV 25520
  31.  
  32. **********************************************************************/
  33.  
  34. // restore a file for editing
  35. proc RestoreEdit()
  36.         integer theline,therow
  37.  
  38.         theline = val(GetText(8,5))
  39.         therow  = val(GetText(14,2))
  40.         editfile(GetText(17,64))
  41.         GotoLine(theline)
  42.         ScrollToRow(therow)
  43. end
  44.  
  45.  
  46. // restore a bookmark
  47. proc RestoreMark()
  48.         string themark[1]
  49.  
  50.         themark = gettext(6,1)
  51.         restoreedit()
  52.         PlaceMark(themark)
  53. end
  54.  
  55.  
  56. // restore the video mode
  57. proc RestoreVid()
  58.         set(CurrVideoMode,Val(GetText(8,5)))
  59. end
  60.  
  61. // parse the STATUS.TSE file and restore the status of the editor
  62. proc mRestoreEdit()
  63.         integer statfile,i=1
  64.         string mode[4]
  65.  
  66.         editfile("status.tse")
  67.         statfile = getbufferid()
  68.         while (i <= numlines())
  69.                 gotoline(i)
  70.                 mode = gettext(1,4)
  71.                 case mode
  72.                         when "edit"
  73.                                 RestoreEdit()
  74.                         when "mark"
  75.                                 RestoreMark()
  76.                         when "vid "
  77.                                 RestoreVid()
  78.                 endcase
  79.                 gotobufferid(statfile)
  80.                 i = i + 1
  81.         endwhile
  82.         abandonfile()
  83. end
  84.  
  85.  
  86. // if there is a file STATUS.TSE, use it to restore the editor
  87. proc mLoadFromStat()
  88.  
  89.         if fileexists("status.tse")
  90.                 mrestoreedit()
  91.         endif
  92. end
  93.  
  94.  
  95. // save the current bookmarks. flist is the buffer id of the output file
  96. proc mSaveMarks(integer flist)
  97.     integer i=1
  98.     string themark[1]
  99.     string s[80]
  100.  
  101.     while i <= 26
  102.         themark = (Chr(Asc('a') + i - 1))
  103.         if GotoMark(themark)
  104.             // if mark there, add it to list of marks
  105.             s = Format('mark ', themark:1,' ', currline():5,' ',
  106.                        currrow():2,' ',currfilename())
  107.             GotoBufferId(flist)
  108.             AddLine(s)
  109.         endif
  110.         i = i + 1
  111.     endwhile
  112. end
  113.  
  114.  
  115. // save the currently open files and their positions
  116. proc mSavePositions(integer flist, integer start)
  117.         integer temp
  118.         string s[80]
  119.  
  120.         gotobufferid(start)
  121.         repeat
  122.                 if (query(buffertype) == _NORMAL_)
  123.                         temp = getbufferid()
  124.                         s = format('edit   ',currline():5,' ',currrow():2,' ',currfilename())
  125.                         gotobufferid(flist)
  126.                         addline(s)
  127.                         gotobufferid(temp)
  128.                 endif
  129.                 nextfile()
  130.         until (getbufferid() == start)
  131.         gotobufferid(flist)
  132. end
  133.  
  134.  
  135. // save all status and save all files and exit
  136. proc mSaveStatAndExit ()
  137.         integer start, flist, temp
  138.         string s[80]
  139.  
  140.         start = getbufferid()
  141.         flist = createtempbuffer()
  142.         s = format('vid   ',query(currvideomode):5)
  143.         addline(s)
  144.         mSaveMarks(flist)
  145.         mSavePositions(flist,start)
  146.         saveas("status.tse",_OVERWRITE_)
  147.         abandonfile()
  148.         saveallandexit()
  149. end
  150.  
  151. // --------------------------------------------------------------------
  152.  
  153. // this is the modified WHENLOADED()
  154.  
  155. proc WhenLoaded()
  156.     integer cid = GetBufferId()
  157.  
  158.     pick_buffer = CreateTempBuffer()
  159.     GotoBufferId(cid)
  160.     Hook(_ON_CHANGING_FILES_, OnChangingFiles)
  161.     Hook(_ON_FIRST_EDIT_, OnFirstEdit)
  162.  
  163.     if (length(query(doscmdline)) == 0)
  164.         mloadfromstat()
  165.     endif
  166. end
  167.  
  168.